package com.hanhai;


import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

/**
 * @Author weijingchen
 * @Date 2025/5/27 6:55
 * @Version 1.0.0
 */
public class ChronoUnitTest {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime dateTime = LocalDateTime.of(2000, 1, 1, 0, 0, 0);

        long years = ChronoUnit.YEARS.between(dateTime, now);
        System.out.println("相差的年数："+  years);

        long months = ChronoUnit.MONTHS.between(dateTime, now);
        System.out.println("相差的月数："+  months);

        long days = ChronoUnit.DAYS.between(dateTime, now);
        System.out.println("相差的日数："+  days);

        long hours = ChronoUnit.HOURS.between(dateTime, now);
        System.out.println("相差的小时数："+  hours);

        long minutes = ChronoUnit.MINUTES.between(dateTime, now);
        System.out.println("相差的分钟数："+  minutes);

        long seconds = ChronoUnit.SECONDS.between(dateTime, now);
        System.out.println("相差的秒数："+  seconds);

        long millis = ChronoUnit.MILLIS.between(dateTime, now);
        System.out.println("相差的毫秒数："+  millis);

        long micros = ChronoUnit.MICROS.between(dateTime, now);
        System.out.println("相差的微秒数："+  micros);

        long nanos = ChronoUnit.NANOS.between(dateTime, now);
        System.out.println("相差的纳秒数："+  nanos);

        long halfDays = ChronoUnit.HALF_DAYS.between(dateTime, now);
        System.out.println("相差的半天数："+  halfDays);

        long weeks = ChronoUnit.WEEKS.between(dateTime, now);
        System.out.println("相差的周数："+  weeks);



    }
}
